/******************************************************************************
 * @file  gkt_bitband.h
 * @date  17/Apr/2019
 ******************************************************************************/

#ifndef GKT_BITBAND_H
#define GKT_BITBAND_H

#include "gkt_core.h"
#include "gkt_defines.h"
#include "gkt_debug.h"

#if defined(GKT_CORE_BITBAND_SUPPORT) && GKT_CORE_BITBAND_SUPPORT

#define GKT_BITBAND_SUPPORT	1

/********************************************************************************
 * A bit-band region maps each word in a bit-band alias region 
 * to a single bit in the bit-band region.
 *
 * A word access to an alias region maps to a single bit in the ait-band region.
 *
 * The Memory model may support mapping multiple regions.
 *
 ********************************************************************************
 *                  Bit-band Region    Alias Region
 ********************************************************************************
 *                  ----------          --------------------
 * addrBB + 0x00 ==> | Word 0 |  <--->  | bit 00 of Word 0 | <== addrA + 0x00
 *                  ----------     |    --------------------
 *                                 |->  | bit 01 of Word 0 | <== addrA + 0x04
 *                                 |    --------------------
 *                                 |->  |      ... ...     |
 *                                 |    --------------------
 *                                 |->  | bit 31 of Word 0 | <== addrA + 0x7C
 *                   ----------         --------------------        
 * addrBB + 0x04 ==> | Word 1 |  <--->  | bit 00 of Word 1 |  <== addrA + 0x80
 *                   ----------    |    --------------------
 *                                 |->  | bit 01 of Word 1 |  <== addrA + 0x84
 *                                 |    --------------------
 *                                 |->  |      ... ...     |
 *                                 |    --------------------
 *                                 |->  | bit 31 of Word 1 |  <== addrA + 0xFC
 *                                      --------------------
 *
 * addrA = addrA_Base + ((addrBB - addrBB_Base) << 5)
 *
 * addrR      : address in Bit-band Region
 * addrR_Base : Bit-band Region Base Address
 * addrA      : address in Alias Region
 * addrA_Base : Alias Region Base Address
 ********************************************************************************/

#define GKT_BITBAND_ALIAS_ADDR(name, bb_addr)	\
	(GKT_BITBAND_##name##_ALIAS_ADDR + (((uint32_t)(bb_addr) - GKT_BITBAND_##name##_BITBAND_ADDR) << 5))

#else
#define GKT_BITBAND_SUPPORT	0
#endif

#endif	/* GKT_BITBAND_H */

